package com.ddwl.gate.feign;

import cn.hutool.core.io.IoUtil;
import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import feign.Response;
import feign.codec.Decoder;
import org.springframework.context.annotation.Bean;

import java.io.InputStream;
import java.lang.reflect.Type;
import java.nio.charset.Charset;

/**
 *
 * @author zach
 * @Date :2020-05-26 16:26.
 */
public class GateFeignConfig {

    @Bean
    public Decoder jsonDecoder(){
        return (Response response, Type type)->{
            InputStream inputStream = response.body().asInputStream();
            String body = IoUtil.read(inputStream, Charset.forName("UTF-8"));
            return body;
        };
    }

    @Bean
    Logger.Level feignLoggerLevel() {
        return Logger.Level.BASIC;
    }

    @Bean
    public RequestInterceptor headerInterceptor() {
        return (RequestTemplate requestTemplate) -> {

        };
    }
}
